<template>
  <div class="knowledge">
    <div class="daohan">
      <dao-han :daohan_index="5"></dao-han>
    </div>
    <div class="liebiao">
      <p class="pp">养宠小知识</p>
      <div class="cha">
        <el-input v-model="input"
                  style="width: 540px"
                  placeholder="请输入您要查找的内容"
                  prefix-icon="Search"
                  clearable />
        <p class="chazhao"
           @click="search">查找</p>
        <p class="chazhao"
           @click="chongzhi">重置</p>
      </div>
      <div class="lists"
           v-for="item in xzslist1"
           :key="item.knowledge_id">
        <div class="title">
          <p class="tou">{{item.title}}</p>
          <p class="shijian">发布时间：{{item.knowledge_time}}</p>
        </div>
        <div class="content">
          <span>
            {{ item.content }}
          </span>
        </div>
      </div>
    </div>
    <el-dialog v-model="centerDialogVisible"
               width="500"
               title="暂时没有您要查找的内容！！！"
               center
               :align-center='true'>
      <span>

      </span>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取消</el-button>
          <el-button type="primary"
                     @click="centerDialogVisible = false">
            确定
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>



<script>
import { onMounted, ref } from 'vue'
import DaoHan from '@/components/daohan/DaoHan.vue'
import { ElMessage } from 'element-plus'
import axios from '@/axios'
export default {
  components: {
    DaoHan
  },
  setup() {
    //小知识列表
    let xzslist = ref('')
    let xzslist1 = ref('')
    //搜索框
    let input = ref('')
    const search = () => {
      if (input.value == '') {
        ElMessage({
          message: '搜索框为空',
          type: 'error'
        })
        xzslist1.value = xzslist.value
      } else {
        // 过滤数据
        xzslist1.value = xzslist.value.filter((item) => {
          return item.title.includes(input.value)
        })
        if (xzslist1.value.length == 0) {
          centerDialogVisible.value = true
          input.value = ''
          xzslist1.value = xzslist.value
        }
      }
    }
    // 搜索框重置
    const chongzhi = () => {
      input.value = ''
      xzslist1.value = xzslist.value
    }
    // 弹窗
    let centerDialogVisible = ref(false)
    onMounted(() => {
      //获取养宠小知识列表
      axios
        .get('/knowledge')
        .then((d) => {
          xzslist.value = d
          xzslist1.value = d
        })
        .catch((err) => console.log(err))
    })

    return {
      xzslist,
      input,
      search,
      xzslist1,
      centerDialogVisible,
      chongzhi
    }
  }
}
</script>

<style scoped lang="less">
.knowledge {
  width: 1200px;
  height: 100%;
  margin: 0 auto;
  padding-bottom: 50px;
  .liebiao {
    width: 1000px;
    margin: 0 auto;
    .pp {
      width: 800px;
      height: 80px;
      margin: 10px auto 0;
      font-size: 30px;
      font-weight: 600;
      color: #eaa40d;
      text-align: center;
      line-height: 80px;
      border-radius: 15px;
      background-color: #fcfcfa;
      border-bottom: #cdbf62 2px solid;
      border-left: #cdbf62 2px dashed;
      border-right: #cdbf62 2px dashed;
      border-top: #cdbf62 2px solid;
    }
    .cha {
      height: 60px;
      display: flex;
      align-items: center;
      padding: 0 180px;
      border: #cdbf62 2px solid;
      margin-top: 20px;
      .chazhao {
        width: 80px;
        height: 30px;
        margin-left: 20px;
        line-height: 30px;
        font-size: 16px;
        font-weight: 600;
        color: #eaa40d;
        text-align: center;
        border-radius: 15px;
        background-color: #fcfcfa;
        border-bottom: #cdbf62 2px solid;
        border-left: #cdbf62 2px solid;
        border-right: #cdbf62 2px solid;
        border-top: #cdbf62 2px solid;
        cursor: pointer;
      }
    }
    .lists {
      width: 100%;
      padding: 20px;
      margin-top: 20px;
      border-radius: 15px;
      border-bottom: #cdbf62 2px solid;
      border-left: #cdbf62 2px dashed;
      border-right: #cdbf62 2px dashed;
      border-top: #cdbf62 2px solid;
      .title {
        height: 40px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20px;
        .tou {
          font-weight: 600;
          width: 600px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .shijian {
          font-size: 14px;
        }
      }
      .content {
        width: 100%;
        font-size: 16px;
        background-color: #fcfcfa;
        padding: 20px;
        span {
          text-indent: 2em;
        }
      }
    }
  }
}
.daohan {
  width: 100vw;
  position: fixed;
  top: 0;
  z-index: 3;
}
</style>

